
layui.use(['form', 'layedit', 'table'], function () {
    var form = layui.form, layer = layui.layer;
    var table = layui.table;

    //监听提交，发送请求
    form.on('submit(add)', function (data) {
        if (data.field.pswd != data.field.userPasswordAgen) {
            layer.alert('两次密码输入不一致');
            return false;
        }
        $.post("${basePath}/user/add", data.field, function (data) {
            // 获取 session
            if (data.status != 200) {
                layer.alert(data.message, {offset: 't', icon: 2});
            }
            if (data.status == 200) {
                layer.alert(data.message, {offset: 't', icon: 1}, function (index) {
                    layer.close(index);
                    var index2 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index2);
                });

            }
        });
        return false;
    });

});

layui.config({
    base: '${basePath}/plugins/layui-treeselect/src/js/' //自定义组件的目录--相对路径
}).use(['form', 'treeselect'], function () {
    var form = layui.form, treeselect = layui.treeselect;

    var data = [];
    $.ajax({
        async: false,
        type: "GET",
        url: "${basePath}/role/getAllRole",
        dataType: "json",
        success: function (resule) {
            data = resule;
        }
    });

    //通过调用render方法进行渲染 [render支持链式调用]
    treeselect.render({ //渲染第一个
        elem: '#treeselect1', //这个设置必要为id属性且必须加上#号
        data: data
    });

});
